package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFile;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Setmeal;
import com.sky.entity.SetmealDish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishItemVO;
import com.sky.vo.SetmealVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface SetmealMapper {

    /**
     * 分页查询
     * @param setmealPageQueryDTO
     * @return
     */
    Page<SetmealVO> getPage(SetmealPageQueryDTO setmealPageQueryDTO);
    /**
     * 根据套餐id查询套餐
     * @param id
     * @return
     */
    Setmeal getMealById(Long id);
    /**
     * 根据id查询套餐相关的菜品信息
     * @param setmealId
     * @return
     */
    List<SetmealDish> getSetMealWithDishById(Long setmealId);
    /**
     * 更新套餐的基本信息
     * @param setmeal
     */
    @Update("update setmeal set category_id = #{categoryId}, description = #{description},image = #{image},name = #{name}," +
            "price = #{price},status = #{status} where id = #{id}")
    void  updateBaseSetMeal(Setmeal setmeal);
    /**
     * 更新套餐的菜品信息
     * @param dishId
     */
    @Update(" update setmeal_dish set name = #{name},\n" +
            "                                price = #{price},\n" +
            "                                copies = #{copies}\n" +
            "                                where dish_id = #{dishId}")
    void updateDish(Long dishId);
    @AutoFile(value = OperationType.INSERT)
    void saveBaseSetMeal(Setmeal setmeal);
    /**
     * 插入菜品
     * @param setmealDishes
     */
    void insertSetMeal(List<SetmealDish> setmealDishes);
    @AutoFile(value = OperationType.UPDATE)
    void updateStatusById(Integer status, Integer id);
    /**
     * 根据套餐id删除菜品
     * @param setmealId
     */
    void deleteSetMealWithDish(Long setmealId);
    /**
     * 批量删除
     * @param ids
     */
    void deleteBatch(List<Long> ids);
    /**
     * 动态条件查询套餐
     * @param setmeal
     * @return
     */
    List<Setmeal> list(Setmeal setmeal);
    /**
     * 根据套餐id查询菜品选项
     * @param setmealId
     * @return
     */
    @Select("select sd.name, sd.copies, d.image, d.description " +
            "from setmeal_dish sd left join dish d on sd.dish_id = d.id " +
            "where sd.setmeal_id = #{setmealId}")
    List<DishItemVO> getDishItemBySetmealId(Long setmealId);
}
